//
//  @ Project : Galaxy Star Trading System
//  @ File Name : RuntimeDateTime.h
//  @ Date : 2014/9/5
//  @ Author :
//
//


#if !defined(_CRUNTIMEDATETIME_H_H)
#define _CRUNTIMEDATETIME_H_H

namespace GSTrader
{
	namespace QuoteService
	{
		class QUOTE_SERVICE_API CRuntimeDateTime;

		class QUOTE_SERVICE_API CTimer : public CMsg
		{
		public:
			CTimer(TimerFunc& pFunc, CTimePoint& t, CMsg* pMsg );
			virtual ~CTimer();

			void Execute();

			CTimer(const CTimer& r);
			CTimer& operator = (const CTimer& r);
		public:
			int m_nTimerId;
			CMsg*  m_pMsg;
			CRuntimeDateTime* m_pTimeObject;
			TimerFunc m_pTimerFunc;
		};

		class QUOTE_SERVICE_API CTimerQueue : public CSortMsgQueue
		{
		public:
			CTimerQueue();
			virtual ~CTimerQueue();

			void RemoveTimer(int nTimerId);
			void RemoveAll();
		};

		class QUOTE_SERVICE_API CRuntimeDateTime
		{
		public:
			CRuntimeDateTime(int nType, int nMode);
			virtual ~CRuntimeDateTime();

			CTimePoint GetTime();
			CTimePoint GetNowTime();
			bool SetTime(CTimePoint t);
			int AddTimer(CTimer* pTimer);
			int AddTimer3(TimerFunc& pFunc, CTimePoint& t, CMsg* pMsg);

			void RemoveTimer(int nId);

		public:
			atomic<int> m_nNextId;
			int m_nMode;
			int m_nType;
			CTimePoint m_time;
			CTimerQueue* m_pTimerQueue;
		};
	}
}

#endif // _CRUNTIMEDATETIME_H_H